<?php
defined('IN_ADMIN') or exit('No permission resources.');
$show_validator = $show_scroll = $show_dialog = 1;
include $this->admin_tpl('header', 'admin');
?>
<style type="text/css">
	.list-dot-othors li{width: 16%;}
</style> 
<?php 
    $sname_self_flag = true;#检测当前source_name是否在系统的来源名称库里
    $ssname_all = array();#所有的来源名称
    if($source_name){//如果当前source_name不为空则进行判断
        foreach($this->setting as $v){
            $ssname_all[]=$v['source_name'];
        }
        if (in_array($source_name, $ssname_all)){
            $sname_self_flag=false;
        }
        unset($ssname_all);
    }
?>
<script language="javascript" type="text/javascript" src="<?php echo JS_PATH?>content_addtop_new.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo JS_PATH?>colorpicker.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo JS_PATH?>hotkeys.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo JS_PATH?>cookie.js"></script>
<script type="text/javascript" src="<?php echo JS_PATH?>swfupload/swf2ckeditor.js"></script>
<script>
function ValidateValue(textbox) {
	var IllegalString = "[`~!#$^&*()=|{}':;'\\[].<>/?~#";
	var textboxvalue = textbox.value;
	var index = textboxvalue.length - 1;
	 
	var s = textbox.value.charAt(index);
	 
	if (IllegalString.indexOf(s) > 0) {
		alert('非法字符：'+s);
		s = textboxvalue.substring(0, index);
		textbox.value = s;
		return false;
	}
}
$(function(){
	$('#s_sname').change(function(){
		var source_name = $(this).val();
	    if(source_name=="yes"){  
	        $('#self_sname').css('display','block');
	        $('#self_sname').focus();
	    }else if(source_name=="no"){ 
	        //alert('no');
	        $('#self_sname').css('display','none');
	    } 
	})
})
</script>
<form method="post" action="?m=<?php echo ROUTE_M;?>&c=<?php echo ROUTE_C;?>&a=<?php echo ROUTE_A;?>&id=<?php echo $id;?>&source_type=<?=$source_type?>" id="myform">
	<div class="pad-10">
		<div class="col-tab">
			<div id="div_setting_1" class="contentList pad-10">
				<table width="100%" class="table_form ">
					<tbody>
						<tr>
							<th width="200"><?php echo L('information_name')?>：</th>
							<td><input name="information[title]" id="title" class="input-text" type="text" size="40" value="<?=$title?>" onkeyup="ValidateValue(this)"></td>
						</tr>
						<tr>
							<th width="200"><?php echo L('information_keywords')?>：</th>
							<td><input name="information[keywords]" id="keywords" class="input-text"
								type="text" size="40" value="<?=$keywords?>" onkeyup="ValidateValue(this)"><span style="color: red;font-size:18px;"><strong>注意：</strong>多关键字之间用","隔开</span></td>
						</tr>
						<tr>
							<th width="100"><?php echo L('type')?>：</th>
							<td>
								<select name="information[type_id]" >
									<option value="0">请选择</option>
									<?php echo $types;?>
								</select>	
							</td>
						</tr>
						<tr>
							<th width="200">所属赛事 :</th>
							<td>
								<select name="contestid" >
									<option value="0">请选择</option>
									<?php echo $categorys;?>
								</select>
							</td>
						</tr>
						<tr>
							<th width="200"><?php echo L('source_name')?>：</th>
							<td><select name="information[source_name]" id="source_name">
								<option value="" selected="">请选择</option>
								<?php foreach($this->setting as $v){?>
								<option value="<?php echo $v['source_name'];?>" <?php if ($v['source_name'] == $source_name){?> selected <?php }?>><?php echo $v['source_name'];?></option>
								<?php }?>
								</select>
								<?php echo form::select(array('2'=>'外部采集', '1'=>'站内添加'), $source, 'name="information[source]"')?>
								&nbsp;&nbsp;是否编辑<b>来源名称</b>：<select name='information[sname_manual_flag]' id='s_sname'>
								    <option value='no'>否</option>
								    <option value='yes'<?php if ($sname_self_flag) {
								        echo 'selected';
								    }?>>是</option>
								</select>&nbsp;<span style='color:red;font-weight:bold;'>来源名称如需手动输入，请选择"是"；默认为"否"！</span><br><input style='display:<?php echo $sname_self_flag?'block':'none'?>;' type='text' name='information[sname_manual]' id='self_sname' placeholder='请在此输入要编辑的来源名称...' size=30 value='<?=$source_name?>'>
								</td>
						</tr>
						<tr>
							<th width="200"><?php echo L('source_link')?> :</th>
							<td>
								<input name="information[source_link]" class="input-text" value="<?=$source_link?>" id="source_link" type="text" size="40">
							</td>
						</tr>
						<tr>
							<th width="200"><?php echo L('source_author')?> :</th>
							<td>
								<input name="information[source_author]" class="input-text" value="<?=$source_author?>" type="text" size="40">
							</td>
						</tr>
						<tr>
							<th width="200"><?php echo L('author_logo')?> :</th>
							<td>
								<?php echo form::images('information[author_logo]', 'author_logo', $author_logo, 'information', '', 40)?>
							</td>
						</tr>
						<tr>
							<th width="200"><?php echo L('author_title')?> :</th>
							<td>
								<select name="information[author_title]">
								<option value="" selected="">请选择</option>
								<?php foreach($this->author_title as $v){?>
								<option value="<?php echo $v;?>" <?php if ($v == $author_title){?> selected <?php }?>><?php echo $v;?></option>
								<?php }?>
								</select>
							</td>
						</tr>
						<tr>
							<th width="200">报名链接：</th>
							<td><input name="information[sign_link]" class="input-text" value="<?=$sign_link?>" type="text" size="40" ></td>
						</tr>
						<tr>
							<th width="200"><?php echo L('publish_time')?>：</th>
							<td><?php echo form::date('information[publish_time]',($publish_time>0?$publish_time:date('Y-m-d H:i:s')),10,0,'false');?></td>
						</tr>
						<tr>
							<th><?php echo L('information_image_cover')?>：</th>
							<td><?php echo form::images_crop('information[image_cover]', 'image_cover', $image_cover)?></td>
						</tr>
						<tr>
							<th>竖行图：</th>
							<td><?php echo form::images_crop('information[image_vertical]', 'image_vertical', $image_vertical)?></td>
						</tr>
						<tr>
							<th><?php echo L('info_brief')?>：</th>
							<td><textarea name="information[info_brief]" id="info_brief"
									cols="100" rows="8" onkeyup="ValidateValue(this)"><?=$info_brief?></textarea></td>
						</tr>
						<tr>
							<th width="200"><?php echo L('is_hot')?>：</th>
							<td>
								<?php echo form::radio(array('1'=>'是', '0'=>'否'), $is_hot, 'name="information[is_hot]"')?>
							</td>
						</tr>
						<tr>
							<th width="200"><?php echo L('is_recommended')?>：</th>
							<td>
								<?php echo form::radio(array('1'=>'是', '0'=>'否'), $is_recommended, 'name="information[is_recommended]"')?>
							</td>
						</tr>
						<tr>
							<th width="200"><?php echo L('page_style')?>：</th>
							<td>
								<?php echo form::select(array('1'=>'分页', '2'=>'不分页'), 2, 'name="information[page_style]"')?>
							</td>
						</tr>
						<tr>
							<th width="200"><?php echo L('info_detail')?>：</th>
							<td>
							<textarea name="information[info_detail]" id="info_detail"><?php echo $info_detail?></textarea>
							<?php echo form::editor('info_detail','full','','','',1,1)?>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
			<div class="bk15"></div>
			<!-- <input name="dosubmit" type="submit" value="<?php echo L('submit')?>"
				class="button"> -->
		</div>
	</div>
	<div class="fixed-bottom">
		<div class="fixed-but text-c">
	    <div class="button"><input value="保存并关闭" type="submit" name="dosubmit" class="cu" style="width:145px;" onclick="refersh_window()"></div>
	    <div class="button"><input value="关闭(X)" type="button" name="close" onclick="refersh_window();close_window();" class="cu" style="width:70px;"></div>
	      </div>
	</div>
</form>
</body>
</html>
<script type="text/javascript">
function load_file_list(id) {
	$.getJSON('?m=admin&c=category&a=public_tpl_file_list&style='+id+'&module=special&templates=index|list|show&name=special', function(data){$('#index_template').html(data.index_template);$('#list_template').html(data.list_template);$('#show_template').html(data.show_template);});
}

function import_info(url, title, msgID, htmlID, valID) {
	window.top.art.dialog({id:'selectid',iframe:url, title:title, width:'600', height:'400', lock:true},
		function(){
			var d = window.top.art.dialog({id:'selectid'}).data.iframe;
			var form = d.document.getElementById(msgID);
			var text = form.value;
			var data = text.split('|');
			if (data[2]) {
				$('#'+htmlID).html('<ul id="relation_'+htmlID+'" class="list-dot"><li><span>'+data[2]+'</span><a onclick="remove_relation(\''+htmlID+'\', \''+valID+'\')" class="close" href="javascript:;"></a></li></ul>');
			} else {
				var dosubmit = d.document.getElementById('dosubmit');
				dosubmit.click();
				$('#'+htmlID).html('<ul id="relation_'+htmlID+'" class="list-dot"><li><span>'+text+'</span><a onclick="remove_relation(\''+htmlID+'\', \''+valID+'\')" class="close" href="javascript:;"></a></li></ul>');
			}
			$('#'+valID).val(text);
			window.top.art.dialog({id:'selectid'}).close();
			return false;
		},
		function(){
			window.top.art.dialog({id:'selectid'}).close();
		});void(0);
}

function remove_relation(htmlID, valID) {
	$('#relation_'+htmlID).html('');
	$('#'+valID).val('');
}

function addItem() {
	var n = $('#option_list').find('input[name]').length/3+1;
	var newOption =  '<div class="mb6"><span><?php echo L('type_name')?>：<input type="text" name="type['+n+'][name]" class="input-text" size="15">&nbsp;&nbsp;<?php echo L('type_path')?>：<input type="text" name="type['+n+'][typedir]" class="input-text" size="15">&nbsp;&nbsp;<?php echo L('listorder')?>：<input type="text" name="type['+n+'][listorder]" value="'+n+'" size="6" class="input-text" ></span>&nbsp;<a href="javascript:;" onclick="descItem(this, '+n+');"><?php echo L('remove')?></a></div>';
	$('#option_list').append(newOption);
}

function descItem(a, id) {
	$(a).parent().append('<input type="hidden" name="type['+id+'][del]" value="1">');
	$(a).parent().fadeOut();
}

function SwapTab(name,cls_show,cls_hide,cnt,cur){
	for(i=1;i<=cnt;i++){
		if(i==cur){
			 $('#div_'+name+'_'+i).show();
			 $('#tab_'+name+'_'+i).attr('class',cls_show);
		}else{
			 $('#div_'+name+'_'+i).hide();
			 $('#tab_'+name+'_'+i).attr('class',cls_hide);
		}
	}
}

$(document).ready(function(){
	$.formValidator.initConfig({formid:"myform",autotip:true,onerror:function(msg,obj){window.top.art.dialog({content:msg,lock:true,width:'220',height:'70'}, function(){this.close();$(obj).focus();})}});
	$('#title').formValidator({autotip:true,onshow:"<?php echo L('please_input_title')?>",onfocus:"<?php echo L('please_input_title')?>",oncorrect:"<?php echo L('true')?>"}).inputValidator({min:1,onerror:"<?php echo L('please_input_title')?>"})
});
$("input:radio[name='special[ishtml]']").click(function (){
	if($("input:radio[name='special[ishtml]'][checked]").val()==0) {
		$("#file_div").hide();
	} else if($("input:radio[type='radio'][checked]").val()==1) {
		$("#file_div").show();
	}
});

<!--
//只能放到最下面
var openClose = $("#RopenClose"), rh = $(".addContent .col-auto").height(),colRight = $(".addContent .col-right"),valClose = getcookie('openClose');
$(function(){
	if(valClose==1){
		colRight.hide();
		openClose.addClass("r-open");
		openClose.removeClass("r-close");
	}else{
		colRight.show();
	}
	openClose.height(rh);
	
/*
 * 加载禁用外边链接
 */

	$('#linkurl').attr('disabled',true);
	$('#islink').attr('checked',false);
	$('.edit_content').hide();
	jQuery(document).bind('keydown', 'Alt+x', function (){close_window();});
})
document.title='<?php echo L('add_content');?>';
self.moveTo(-4, -4);
function refersh_window() {
	setcookie('refersh_time', 1);
}
openClose.click(
	  function (){
		if(colRight.css("display")=="none"){
			setcookie('openClose',0,1);
			openClose.addClass("r-close");
			openClose.removeClass("r-open");
			colRight.show();
		}else{
			openClose.addClass("r-open");
			openClose.removeClass("r-close");
			colRight.hide();
			setcookie('openClose',1,1);
		}
	}
)
//-->

</script>
<script type="text/javascript">
	$(function(){
		$('#source_name').change(function(){
			var source_name = $(this).val();
			if (!source_name) {
				$('#source_link').attr('value','');$('#source_link').attr('readonly', false);return false;
			}
			$.ajax({
				type:"get",
				url:"?m=picture&c=picture&a=ajaxSourceLink&pc_hash=<?php echo $_SESSION['pc_hash'];?>&source_name="+source_name,
				dataType: "json",
				success:function(data){
					if(data['status']){
						$('#source_link').attr('value',data['source_link']);
						$('#source_link').attr('readonly', true);
					}
				}
			})
		})
	})
</script>